package com.tiancheng.trade.settlement.controller.admin;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.service.settlement.ISettlementSituation;
import com.tiancheng.trade.settlement.vo.settlement.admin.SettlementSituationQueryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 清分情况
 */
@RestController
@Slf4j
@RequestMapping("/admin/settlementSituation")
public class SettlementSituationController {

    @Autowired
    ISettlementSituation settlementSituationService;


    /**
     * 更新清分情况报表数据
     *
     * @param settlementSituationQueryVO
     * @return
     */
    @PostMapping("/updateReport")
    public Result updateReport(@RequestBody SettlementSituationQueryVO settlementSituationQueryVO) {
        return Result.success(settlementSituationService.updateReport(settlementSituationQueryVO));
    }

    /**
     * 分页查询
     *
     * @param settlementSituationQueryVO 查询条件
     * @return
     */
    @GetMapping("/query")
    public Result query(SettlementSituationQueryVO settlementSituationQueryVO) {
        return Result.success(settlementSituationService.query(settlementSituationQueryVO));
    }

    /**
     * 清分情况报表导出
     *
     * @param settlementSituationQueryVO
     * @return
     */
    @PostMapping("/export")
    public Result settlementSituationExport(@RequestBody SettlementSituationQueryVO settlementSituationQueryVO, HttpServletRequest request, HttpServletResponse response) throws IOException {
        settlementSituationService.export(settlementSituationQueryVO, request, response);
        return Result.success("导出成功");
    }

    /**
     * 差额订单导出
     *
     * @param vo
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/diffOrderExport")
    public Result diffOrderExport(@RequestBody SettlementSituationQueryVO vo, HttpServletRequest request, HttpServletResponse response) throws IOException {
        settlementSituationService.diffOrderExport(vo.getReportTime(), request, response);
        return Result.success("导出成功");
    }

}
